﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;
using mydddd.BLL.other;
using Maticsoft.DBUtility;
namespace mydddd.Web.Demo.sysRolepopedom
{
    public partial class RoleList : BasePage
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                bind();
            }
        }

        private void bind()
        {
            //Grid1.PageSize = int.Parse(ddlPageSize.SelectedValue);
            string columns = @" * ";
           
            if (cb_del.Checked)
            {
                Button_delete.Text = "批量还原";
                Button_delete.Icon = Icon.ArrowUp;
                BindFineUI_del(columns, Grid1, "sysRolepopedom", "", "id");
            }
            else
            {
                Button_delete.Text = "批量删除";
                Button_delete.Icon = Icon.Delete;
                BindFineUI2(columns, Grid1, "sysRolepopedom", "", "id"); ;
            }

        }
       

        #region gird常用方法
        //添加
        protected void Button_add_OnClick(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(
                   Window1.GetShowReference("RoleAdd.aspx", "添加角色"));

        }

        //删除
        protected void Button_delete_OnClick(object sender, EventArgs e)
        {
            string str = GetDataKeysBySelectedRow(Grid1);
            if (str.Length == 0)
            {
                Alert.Show("请选择记录！");
                return;
            }

            IsDelSet("sysRolepopedom", cb_del.Checked ? 0:1, str);
            bind();
        }

        //每页显示数目
        protected void ddlPageSize_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            bind();
        }
        //分页事件
        protected void Grid1_OnPageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            bind();
        }
        #endregion

        protected void cb_del_OnCheckedChanged(object sender, CheckedEventArgs e)
        {
           bind();
        }

        protected void Window1_OnClose(object sender, WindowCloseEventArgs e)
        {
            bind();
        }

        protected void Btn_updateCache_OnClick(object sender, EventArgs e)
        {
            //更新所有的缓存(删除所有缓存)
            
            //注： 由于登录会自动更新当前角色的页面权限缓存，故再这里只需要删除所有缓存即可。
           
            DBControl db = new DBControl();
            DataTable dt= db.GetDataTable("sysRolepopedom", "id", null);

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    CacheHelper.Remove(BLL.sysRolepopedom.CacheName() + dt.Rows[i]["id"].ToString());
                }
            }

            Alert.Show("更新缓存成功！请刷新页面！");

        }
    }
}